package com.roadmap.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.roadmap.exception.EntityNotFoundException;
import com.roadmap.exception.InvalidQueryException;
import com.roadmap.exception.InvalidValueException;
import com.roadmap.exception.NullObjectException;
import com.roadmap.exception.ServerException;

public interface IActionUtil {
	/**
	 * return the forward which is used in this way. when the same form is being
	 * tried to submit for times, such case will be handled and then forward to
	 * a specific page.
	 */
	public String getSmtForward();

	/**
	 * This method will check if the same action form is already submitted and
	 * processed. If submitted, return true, or else return false.
	 * 
	 * @return: true - the form is submitted again. false - the form is not
	 *          submitted yet
	 */
	public boolean isFormSubmitted(HttpServletRequest request) throws Exception;

	/**
	 * save cookies.
	 * 
	 * @param cooks:
	 *            a set of cookie names
	 * @param values:
	 *            a set of cookie values
	 */
	public void saveCookies(HttpServletResponse response, String[] cooks,
			String[] values, Boolean[] isEncrypted);

	/**
	 * remove cookies
	 * 
	 * @param cooks:
	 *            a set of cookie names
	 */
	public void removeCookie(HttpServletResponse response, String[] cooks);

	/**
	 * check user's permission to execute the action
	 * 
	 * @throws NullObjectException
	 * @throws EntityNotFoundException 
	 */
	public boolean checkPermission(HttpServletRequest request)
			throws NullObjectException, InvalidQueryException, ServerException,
			InvalidValueException, EntityNotFoundException;

	/** indicates if user already logged on the system */
	public boolean isLoggedOn(HttpServletRequest request);

	/**
	 * check if the request is valid. If invalid, return a forward of page that
	 * error message can be shown on; if valid, return NULL.
	 */
	public ActionForward getErrorForward(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception;

	// /** encoding strings from ISO8859-1 to UTF-8*/
	// public void encodingString(Object text);
}
